What is gsap?
GSAP (GreenSock Animation Platform) is a powerful JavaScript library for creating high-performance animations that work in all major browsers. It is widely used for animating web elements, SVGs, and more, providing a rich set of features for developers to create complex animations with ease.
What are gsap's main functionalities?
Basic Tweening
This feature allows you to animate any property of an element over a specified duration. In this example, the element with the class 'element' will move 100 pixels to the right over 1 second.
gsap.to('.element', { duration: 1, x: 100 });
Timeline Animations
Timelines allow you to sequence multiple animations. In this example, 'element1' will move 100 pixels to the right, and then 'element2' will move 100 pixels down, each over 1 second.
const tl = gsap.timeline();
tl.to('.element1', { duration: 1, x: 100 })
.to('.element2', { duration: 1, y: 100 });
Stagger Animations
Staggering allows you to animate multiple elements with a delay between each start. In this example, each element with the class 'elements' will move 100 pixels to the right, starting 0.2 seconds after the previous one.
gsap.to('.elements', { duration: 1, x: 100, stagger: 0.2 });
ScrollTrigger
ScrollTrigger allows you to create animations that are triggered by scrolling. In this example, the element with the class 'element' will move 100 pixels to the right when it enters the viewport.
gsap.registerPlugin(ScrollTrigger);
gsap.to('.element', { scrollTrigger: '.element', x: 100 });
Other packages similar to gsap
animejs
Anime.js is a lightweight JavaScript animation library with a simple, yet powerful API. It supports CSS properties, SVG, DOM attributes, and JavaScript Objects. Compared to GSAP, Anime.js is more lightweight but may lack some of the advanced features and plugins that GSAP offers.
velocity-animate
Velocity is an animation engine with the same API as jQuery's $.animate(). It works with and without jQuery. Velocity is known for its performance and ease of use, but it doesn't offer as many features and plugins as GSAP.
popmotion
Popmotion is a functional, flexible JavaScript animation library. It provides a range of tools for creating animations and interactions. While it is highly modular and flexible, it may require more setup and understanding compared to GSAP's more straightforward API.
GSAP (GreenSock Animation Platform)
GSAP is a framework-agnostic JavaScript animation library that turns developers into animation superheroes. Build high-performance animations that work in every major browser. Animate CSS, SVG, canvas, React, Vue, WebGL, colors, strings, motion paths, generic objects...anything JavaScript can touch! GSAP's ScrollTrigger plugin delivers jaw-dropping scroll-based animations with minimal code. gsap.matchMedia() makes building responsive, accessibility-friendly animations a breeze.
No other library delivers such advanced sequencing, reliability, and tight control while solving real-world problems on over 12 million sites. GSAP works around countless browser inconsistencies; your animations just work. At its core, GSAP is a high-speed property manipulator, updating values over time with extreme accuracy. It's up to 20x faster than jQuery!
GSAP is completely flexible; sprinkle it wherever you want. Zero dependencies.
There are many optional plugins and easing functions for achieving advanced effects easily like scrolling, morphing, animating along a motion path or FLIP animations. There's even a handy Observer for normalizing event detection across browsers/devices.
Get Started
Docs & Installation
View the full documentation here, including an installation guide.
CDN
<script src="https://cdn.jsdelivr.net/npm/gsap@3.12/dist/gsap.min.js"></script>
See JSDelivr's dedicated GSAP page for quick CDN links to the core files/plugins. There are more installation instructions at gsap.com.
Every major ad network excludes GSAP from file size calculations and most have it on their own CDNs, so contact them for the appropriate URL(s).
NPM
See the guide to using GSAP via NPM here.
npm install gsap
GSAP's core can animate almost anything including CSS and attributes, plus it includes all of the utility methods like interpolate(), mapRange(), most of the eases, and it can do snapping and modifiers.
import gsap from "gsap";
import ScrollTrigger from "gsap/ScrollTrigger";
import Flip from "gsap/Flip";
import Draggable from "gsap/Draggable";
import { gsap, ScrollTrigger, Draggable, MotionPathPlugin } from "gsap/all";
gsap.registerPlugin(ScrollTrigger, Draggable, Flip, MotionPathPlugin);
The NPM files are ES modules, but there's also a /dist/ directory with UMD files for extra compatibility.
Download Club GSAP members-only plugins from your gsap.com account and then include them in your own JS payload. There's even a tarball file you can install with NPM/Yarn. GSAP has a private NPM registry for members too. Post questions in our forums and we'd be happy to help.
ScrollTrigger & ScrollSmoother
If you're looking for scroll-driven animations, GSAP's ScrollTrigger plugin is the new standard. There's a companion ScrollSmoother as well.
Using React?
There's a @gsap/react package that exposes a useGSAP()
hook which is a drop-in replacement for useEffect()
/useLayoutEffect()
, automating cleanup tasks. Please read the React guide for details.
Resources
What is Club GSAP?
There are 3 main reasons anyone signs up for Club GSAP:
Learn more.
Try all bonus plugins for free!
https://gsap.com/trial
Need help?
Ask in the friendly GSAP forums. Or share your knowledge and help someone else - it's a great way to sharpen your skills! Report any bugs there too (or file an issue here if you prefer).
License
GreenSock's standard "no charge" license can be viewed at https://gsap.com/standard-license. Club GSAP members are granted additional rights. See https://gsap.com/licensing/ for details. Why doesn't GSAP use an MIT (or similar) open source license, and why is that a good thing? This article explains it all: https://gsap.com/why-license/
Copyright (c) 2008-2023, GreenSock. All rights reserved.